import { defineStore } from 'pinia'
import { ref } from 'vue'
import { userInfoServer } from '@/api/login.js'
export const useUserStore = defineStore(
  'user',
  () => {
    // 页面token
    const token = ref('')
    const setToken = value => {
      token.value = value
    }
    const removeToken = () => {
      token.value = ''
    }
    // 登录页用户账号和密码
    const userInfo = ref({})
    const setUserInfo = obj => {
      userInfo.value = obj
    }
    const removeUserInfo = () => {
      userInfo.value = {}
    }
    // 用户在页面展示的的基本信息
    const userData = ref({})
    const setUserData = async () => {
      const res = await userInfoServer()
      userData.value = res.data
    }
    const removeUserData = () => {
      userData.value = {}
    }
    return {
      token,
      userInfo,
      removeUserInfo,
      setToken,
      removeToken,
      setUserInfo,
      userData,
      setUserData,
      removeUserData
    }
  },
  { persist: true }
)
